package com.sinopec.yelofixedreader.stock.inn.api

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.sinopec.basemodule.http.HttpParamObj
import com.sinopec.basemodule.http.api.HttpResult
import com.sinopec.basemodule.http.api.RetroAPIFactory
import com.sinopec.basemodule.model.AddPalletResultModel
import com.sinopec.basemodule.model.StockInListModel
import com.sinopec.yelofixedreader.stock.inn.model.StockInApiRequestModel
import io.reactivex.Observable

/**
 * @author lwj
 * @ClassName: StockOutApi
 * @Description: 入库模块
 */
object StockInApi {

    private val I_SERVICE: StockInService by lazy {
        RetroAPIFactory.create(StockInService::class.java)
    }

    private val gson: Gson by lazy { Gson() }
    private val parseType = object : TypeToken<HashMap<String, Any?>>() {}.type

    /**
     * 入库-列表页面
     */
    fun searchList(machineCode: String): Observable<HttpResult<List<StockInListModel>?>?>? {
        val hashMap = HttpParamObj.createParams()
            .putParam("machineCode", machineCode)//单据唯一标识
            .end()
        return I_SERVICE.searchList(hashMap)
    }


    /**
     * 确认入库-编码校验
     */
    fun confirmStockInOrder(model: StockInApiRequestModel): Observable<HttpResult<AddPalletResultModel?>?>? {
        val hashMap = HttpParamObj.createParams()
            .putParam("taskRecordId", model.taskRecordId)//单据唯一标识
            .putParam("palletCode", model.palletCode)//托盘编码
            .end()
        return I_SERVICE.confirmStockInOrder(hashMap)
    }


    /**
     * 确认入库完成
     */
    fun confirmStockInOrderFinish(outboundIntegrationId: Long): Observable<HttpResult<Any?>?>? {
        val end = HttpParamObj.createParams()
            .putParam("taskRecordId", outboundIntegrationId)//单据唯一标识
            .end()
        return I_SERVICE.confirmStockInOrderFinish(end)
    }
}